﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Cms.Web.CmsSystem.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>首页</title>
    <asp:PlaceHolder id="BDPageHeader" runat="server"></asp:PlaceHolder>
    <script src="/Scripts/core.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="/Scripts/easyui/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="/Scripts/zTree/jquery.ztree.core-3.4.min.js" type="text/javascript"></script>
    <script src="/Scripts/date.js" type="text/javascript"></script>
    <link href="/Images/Icon.ashx?size=16" rel="stylesheet" type="text/css" />
</head>
<body>
    <div region="north" class="header" style="height: 60px; padding: 0px; border: 0;">
        <div class="toolbar">
            <img src="/Images/logo2.png" width="64px" height="64px" style="float: left;" />
            <div class="sitename">
                XXXXXXX系统</div>
            <div class="info">
                <span class="welcome">欢迎您, <a id="lbusername" href="javascript:;">
                    <% =GetUserName%></a> <span id="lbdate"></span></span><a id="lbLogout" href="Login.aspx?action=logout">
                        注销</a> <a href="javascript:;" id="lbRelogin">重新登录</a>
            </div>
            <b style="clear: both;"></b>
        </div>
    </div>
    <div region="center" style="overflow: hidden; margin: 0; padding: 0; border: 0;">
        <div fit="true" id="maintab" runat="server" style="margin: 0; padding: 0; border: 0;">
        </div>
    </div>
    <script type="text/javascript">
        var TreeJson = {<%=TreeJson%>};
        var curMenu = null, zTree_Menu = null;
        var setting = {
            view: {showLine: true,selectedMulti: false,dblClickExpand: false},
            data: {simpleData: {enable: true}},
            callback: {onNodeCreated: this.onNodeCreated,beforeClick: this.beforeClick,onClick: this.onClick}
        };
        function beforeClick(treeId, node) {
            if (node.isParent) {
               if (node.level === 0) {
                    var pNode = curMenu;
                    while (pNode && pNode.level !== 0) {
                        pNode = pNode.getParentNode();
                    }
                    if (pNode !== node) {
                        var a = $("#" + pNode.tId + "_a");
                        a.removeClass("cur");
                        zTree_Menu.expandNode(pNode, false);
                    }
                    a = $("#" + node.tId + "_a");
                    a.addClass("cur");

                    var isOpen = false;
                    for (var i = 0, l = node.children.length; i < l; i++) {
                        if (node.children[i].open) {
                            isOpen = true;
                            break;
                        }
                    }
                    
                    if (isOpen) {
                        zTree_Menu.expandNode(node, true);
                        curMenu = node;
                    } else {
                        zTree_Menu.expandNode(node.children[0].isParent ? node.children[0] : node, true);
                        curMenu = node.children[0];
                    }
                } else {
                    zTree_Menu.expandNode(node);
                }
            }
            return true//;!node.isParent;
        }
        function onClick(e, treeId, node) {  
            //debugger ;      
            if(node && node.tabtype!=""&& node.tabtype!="OnlyNode"){
                var url="InnerPage.aspx?id="+node.id;
                AddTab($("#"+node.tId),node.name,url,null,node.iconSkin);
            }
            return false ;
        }

        function AddTab(tabFirer,title, href,closeable,icon){  
                if(typeof(closeable)=="undefined" || closeable ==null)
                        closeable =true ;
                var self = $('#maintab').tabs('getSelected');
                //var tabid=$(".centertab",self).attr("id");
                var tt = $(".centertab",self);//$("#"+tabid);  
                if(tt.size()>0){
                var content="";
                if (tt.tabs('exists', title)){//如果tab已经存在,则选中并刷新该tab          
                    tt.tabs('select', title);  
                    refreshTab({tabTitle:title,url:href,tabId:tt.attr("id")});  
                } else {  
                    if (href){  
                         content = '<iframe scrolling="auto" frameborder="0"  _src="'+href+'" style="width:100%;height:100%;"></iframe>';  
                    } else {  
                         content = '未实现';  
                    }  
                    tt.tabs('add',{  
                        title:title,  
                        closable:closeable,  
                        content:content,  
                        iconCls:icon||'icon-default'
                    });  
                }
                }  
        }  

        function refreshTab(cfg){  
            var refresh_tab = cfg.tabTitle?$('#'+cfg.tabId).tabs('getTab',cfg.tabTitle):$('#'+cfg.tabId).tabs('getSelected');  
            if(refresh_tab && refresh_tab.find('iframe').length > 0){  
                var _refresh_ifram = refresh_tab.find('iframe')[0];  
                var refresh_url = cfg.url?cfg.url:_refresh_ifram.src;  
                _refresh_ifram.contentWindow.location.href=refresh_url;  
            } 
        } 
        $(function() {  
            var w = GetInnerWidth();
            var h = GetInnerHeight();
            $("body").css({ width: w + "px", height: h + "px" }).layout({fit:true});
            $("#maintab").tabs({onSelect:function(e,f,g){       
                var self = $('#maintab').tabs('getSelected');
                var tabid=$(".ztree",self).attr("id");
                if(tabid&& tabid !=""){
                    var treejson=TreeJson[tabid];
                    if(treejson && treejson.length>0){
                        $.fn.zTree.init($("#"+tabid), setting, treejson);
                        zTree_Menu = $.fn.zTree.getZTreeObj(tabid);            
                        if(zTree_Menu.getNodes().length>0){
                            curMenu =zTree_Menu.getNodes()[0] ;
                            zTree_Menu.expandNode(curMenu);
                            zTree_Menu.selectNode(curMenu);
                        }
                        else{
                            zTree_Menu.expandNode(zTree_Menu);
                        }
                    $(".layout").layout();
                    //$("#tabs").tabs();  
                    $(".centertab",self).tabs({onBeforeClose:function(title){
                        var _self = $(".centertab",self).tabs('getSelected');
                        _self.find('iframe').remove();                    
                        } ,
                        onSelect:function(c,f,g){
                            //debugger ;
                         var _selfIframe = $(".centertab",self).tabs('getSelected').find('iframe');
                         if(_selfIframe.size()>0){
                        var _src=_selfIframe.attr("_src");
                        _selfIframe.attr("src",_src);
                        }
                        }
                    });
                   
                    }//end if treejson
                }//end if tabid
                }//end onselect
            });//end tab       
        });      

    </script>
</body>
</html>
